﻿using System;

namespace EmbeddedSharp.Core.Function.Maths {

    /// <summary>
    /// Get the sign of the parameter.
    /// 
    /// echo(sign(-2));
    /// -1
    /// </summary>
    public class SignNode : FuncNode {
        public SignNode()
            : base() {
            base.Value = "sign";
        }

        public override object Evaluate()
        {
            if (this.Parameters.Count < 1)
            {
                throw new ArgumentException("usage: sign(number)");
            }

            double result = Convert.ToDouble(
                Parameters[0].Evaluate());

            return System.Math.Sign(result).ToString();
        }
    }
}
